package com.phantasy.globals
{
	import com.phantasy.ui.UISystem;
	
	import mx.core.Singleton;
	
	/**
	 *游戏参数 在具体的项目中此参数需要随着项目的变更而变更
	 * @author Liseen
	 * 
	 */	
	public dynamic class GameParameters
	{
		private static var instance:GameParameters;
		
		public var needToCreate:Boolean=false;
		public var debug:String;
		public var server:String;
		public var account:String;
		public var key:String;
		public var v:String;
		public var tstamp:int;
		public var gateway:Object;
		public var openCache:String;
		public var versionURL:String;
		public var resourceHost:String;
		public var fcm:String;
		private var _init:Boolean;
		
		public function GameParameters(value:Singleton)
		{
			
		}
		
		/**
		 *是否是debug模式
		 * @return 
		 * 
		 */		
		public function isDebug():Boolean
		{
			return (this.debug=="true");
		}
		
		/**
		 *获取主机地址 
		 * @return 
		 * 
		 */		
		public function getGatewayHost():String
		{
			if(this.gateway){
				return this.gateway.host;	
			}
			return "";
		}
		
		
		/**
		 *获取游戏参数对象 
		 * @return 
		 * 
		 */		
		public static function getInstance():GameParameters
		{
			if(GameParameters.instance==null){
				GameParameters.instance = new GameParameters(new Singleton());
			}
			
			return GameParameters.instance;
		}
		
		/**
		 *初始化参数 
		 * @param data
		 * 
		 */		
		public function initParameters(data:Object):void
		{
			var parameters:GameParameters;
			var attribute:String;
			var gateWayStr:String;
			var gateWayList:Array;
			//agent=91wan&server=3&account=102988499&gatewayStr=s3.91wan.shzj.mingchaoonline.com,443&key=c43921d551a02690464fa0718583d8b1&tstamp=1344231806&fcm=1&bgp_host=bgp1.mingchao.com&bgp_port=443&directly_use_bgp=&proxyName=&resourceHost=http://shzj-cdnres.mingchaoonline.com&serviceHost=http://game.shzj.91wan.com/user/&serviceVersion=B_beta0.1.7-20120802.25837.25840&gm_link_3=&recharge=http://pay.91wan.com/?game_id=97|server_id=3&bbs=http://bbs.91wan.com/forum-756-1.html&gameBackgroundPic=&title=91wan山海战纪-双线3服（剑舞轩辕）-- 91wan网页游戏-中国最大的网页游戏平台&openCache=0&v=25840&serverOnlineDate=1343451600&officeSite=http://www.91wan.com/shzj
			data["debug"] = "false"
			data["server"] = 2;
			data["account"] = 102988499;
			data["gatewayStr"] = "s3.91wan.shzj.mingchaoonline.com,443";
			data["key"] = "c43921d551a02690464fa0718583d8b1"
			data["v"] = 23378
			data["tstamp"] = "1344231806";
			data["fcm"] = 1;
			data["proxyName"] = "";
			data["gameBackgroundPic"] = "";
			data["resourceHost"] = "http://shzj-cdnres.mingchaoonline.com";
			
			if((this._init==false)&&data){
				parameters = GameParameters.getInstance();
				//遍历对象绑定属性
				for(attribute in data){
					parameters[attribute] = data[attribute]
				}
				//服务器字符串
				gateWayStr = data.gatewayStr;
				gateWayList = gateWayStr.split(",");
				parameters.gateway = {"host":gateWayList[0],"port":gateWayList[1],"key":gateWayList[2]};
				parameters.versionURL = parameters.v+".txt";
				UISystem.v = parameters.v;
				this._init = true;
			}
		}
		
	}
}
class Singleton 
{
	
	
}